package com.hr.reactive.flux;

import com.hr.reactive.common.Utils;
import reactor.core.publisher.Flux;

public class Lec11FluxGenerate {
    public static void main(String[] args) {
        //最多发送一个值
//        Flux.generate(synchronousSink -> {
//            synchronousSink.next(1);
//            //  synchronousSink.next(2);
//            //   synchronousSink.complete();
//        }).take(4).subscribe(Utils.subscriber());

        demo1();
    }

    private static void demo() {
        Flux.generate(synchronousSink -> {
            var name = Utils.faker().country().name();
            synchronousSink.next(name);
            if (name.equals("Canada")) {
                synchronousSink.complete();
            }
        }).subscribe(Utils.subscriber());
    }
    private static void demo1() {
        Flux.<String>generate(synchronousSink -> {
            var name = Utils.faker().country().name();
            synchronousSink.next(name);
        }).takeUntil(c->c.equals("Canada")).subscribe(Utils.subscriber());
    }
}
